<?php
namespace statistics;
/******************************************************************************
 * PHP-Skript für das ermitteln von Dateipfaden
 * 
 * Copyright    : (c) 2004 - 2013 The Admidio Team
 * Homepage     : http://www.admidio.org
 * License      : GNU Public License 2 http://www.gnu.org/licenses/gpl-2.0.html
 * 
 * 
 *****************************************************************************/

use statistics\utils\SplClassLoader;

// Pfad des Plugins ermitteln
$admidio_folder_pos     = strpos(__FILE__,'adm_plugins');
$admidio_folder_path    = substr(__FILE__,0,($admidio_folder_pos-1));

require_once($admidio_folder_path.'/adm_program/system/common.php');

$plugin_folder_pos      = strpos(__FILE__, 'adm_plugins') + 11;
$plugin_folder_path     = substr(__FILE__,0,$plugin_folder_pos);

$statistics_folder_pos  = strpos(__FILE__, 'statistics') + 10;
$statistics_web_root	= str_replace(DIRECTORY_SEPARATOR, "/",substr(__DIR__, $admidio_folder_pos, $statistics_folder_pos));

// echo "Admidio Path: ".$admidio_folder_path;
// echo "<br />Plugin Path: ".$plugin_folder_path;
// echo "<br />Statistics Web Root: ".$statistics_web_root;

if(!defined('PLUGIN_PATH'))
{
    define('PLUGIN_PATH', $plugin_folder_path);
}

if(!defined('STATISTICS_PATH'))
{
    define('STATISTICS_PATH', __DIR__.DIRECTORY_SEPARATOR);
}

if(!defined('STATISTICS_WEB_ROOT'))
{
	define('STATISTICS_WEB_ROOT', $g_root_path."/".$statistics_web_root);
}
 
// echo "<br />Plugin Path: ".PLUGIN_PATH;
// echo "<br />Statistics Path: ".STATISTICS_PATH;


// function autoloader($classname) {
// 	$includeClass = createFullAutoloadClassPath($classname);
// 	require_once ($includeClass);
// 	echo "Class successfully included: ".$includeClass;
// }

// function createFullAutoloadClassPath ($classname){
// 	$returnClassPath;
// 	$stdClassPath = STATISTICS_PATH.'/utils/classes/' . $classname . '.php';
// 	$hierarchicClassPath = STATISTICS_PATH .'/'.(str_replace('_', '/', $classname)) . '.php';
	
// 	if (file_exists($stdClassPath)){
// 		$returnClassPath = $stdClassPath;
// 	}elseif (file_exists($hierarchicClassPath)){
// 		$returnClassPath = $hierarchicClassPath;
// 	}else{
// 		throw new Exception("could not include class: ".$classname.", ".$stdClassPath.", ".$hierarchicClassPath. " (unknown classname)");
// 	}
	
// 	return $returnClassPath;
// }

// spl_autoload_register('autoloader');


require_once(STATISTICS_PATH.'/config.php');
require_once(STATISTICS_PATH.'/utils/SplClassLoader.php');


// echo "<br />Statistics Web Root: ". STATISTICS_WEB_ROOT;

$classLoader = new SplClassLoader(__NAMESPACE__,PLUGIN_PATH);
$classLoader->register();




?>